<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>v-bind</title>

    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
</head>

<body>
    <div id="box">
        <h1>绑定输入框</h1>
        使用v-model绑定用户名：<input type="text" v-model="rbacManager.username">
        使用v-model绑定密码：<input type="text" v-model="rbacManager.password">
        <br>
        {{rbacManager.username}}---{{rbacManager.password}}
        <hr>
        <h1>绑定多行文本</h1>
        <textarea v-model="textarea" cols="30" rows="10"></textarea><br>
        {{textarea}}
        <hr>
        <h1>绑定复选框</h1>
        爱好：
        <ul>
            <li v-for="(item, index) in hobbies" :key="index">
                <!-- value前面加冒号，表示动态绑定，后面的值是一个表达式 -->
                <input type="checkbox" :value="item" id="item.id" v-model="rbacManager.hobby">
                <label for="item.id">{{item.name}}</label>
            </li>
        </ul>
        {{rbacManager.hobby}}
        <hr>
        <h1>绑定单选按钮</h1>
        <ul>
            <li v-for="(item, index) in sex" :key="index">
                <input type="radio" :value="item" v-model="rbacManager.sex">{{item.name}}
            </li>
        </ul>
        {{rbacManager}}
        <hr>
        <h1>绑定下拉列表</h1>
        <select v-model="rbacManager.city">
            <option disabled value="">请选择</option>
            <option v-for="item in cities" :value="item">
                {{item.name}}
            </option>
        </select><br>
        {{rbacManager}}
    </div>
</body>
<script>
    // 动态地去绑定一些HTML属性时，可以通过v-bind指令来 响应式更新该DOM节点
    new Vue({
        el: "#box",
        data() {
            return {
                rbacManager: {
                    username: "default",
                    password: "123456",
                    hobby: [],
                    sex: 0,
                    city: ""
                },
                cities: [
                    { id: 0, name: "成都" },
                    { id: 1, name: "绵阳" },
                    { id: 2, name: "德阳" },
                    { id: 3, name: "乐山" },
                    { id: 4, name: "眉山" },
                    { id: 5, name: "攀枝花" },
                ],
                sex: [
                    { id: 0, name: "女" },
                    { id: 1, name: "男" },
                    { id: 2, name: "其他" }
                ],
                hobbies: [
                    { id: 0, name: "篮球" },
                    { id: 1, name: "足球" },
                    { id: 2, name: "乒乓球" },
                    { id: 3, name: "台球" },
                    { id: 4, name: "保龄球" }
                ],
                textarea: `
                总结的来说, 要想清楚, 随机一段废话, 到底是一种怎么样的存在. 随机一段废话似乎是一种巧合，但如果我们从一个更大的角度看待问题，这似乎是一种不可避免的事实.  `
            }
        },
    });
</script>

</html>